package com.freak.wanandroid.model.discover;

import com.freak.httpmanager.callback.SubscriberCallBack;
import com.freak.wanandroid.base.repository.BaseRepository;
import com.freak.wanandroid.bean.ArticleListBean;
import com.freak.wanandroid.net.HttpResultFunc;
import com.freak.wanandroid.util.ToolUtils;

import io.reactivex.rxjava3.core.Observable;

/**
 * @author: freak
 * @date: 2022/9/25
 */
public class DiscoverRepository extends BaseRepository {
    /**
     * 收藏文章
     */
    public void doCollect(int id, SubscriberCallBack<String> observer) {
        Observable observable = mApiService.doCollect(id).map(new HttpResultFunc<String>());
        addSubscription(observable, observer);
    }

    /**
     * 获取最新文章
     *
     * @param curPage
     */
    public void getArticle(String curPage, SubscriberCallBack<ArticleListBean> observer) {
        String page = ToolUtils.subtract(curPage, "1");
        Observable observable = mApiService.getArticle("article/list/" + page + "/json").map(new HttpResultFunc<ArticleListBean>());
        addSubscription(observable, observer);
    }

    /**
     * 文章列表中取消收藏
     *
     * @param id
     */
    public void doCancelCollect(int id, SubscriberCallBack<String> observer) {
        Observable observable = mApiService.doCancelCollect(id).map(new HttpResultFunc<String>());
        addSubscription(observable, observer);
    }
}
